home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 012 / argoterm / argoterm.s < prev    next >
Text File  |  1995-03-17  |  49KB  |  1,696 lines

  1. *TITLE: ArgoTerm.S   --  Assembly Language Source Code for Jez's Terminal.
  2. **************************************************************
  3. * *                                                        * *
  4. * * ATerm 0.20, by Jez San, (c)1986 Argonaut Software Ltd. * *
  5. * *                                                        * *
  6. * * 129, The Broadway, Mill Hill, London, NW7 4RN, ENGLAND * *
  7. * *                                                        * *
  8. * *    FrillFree Terminal Software For The Amiga A1000     * *
  9. * *                                                        * *
  10. * *                     -- Freeware --                     * *
  11. * *                                                        * *
  12. **************************************************************
  13.  
  14.  
  15. * Some Include files that might be useful (Most aren't!)
  16.  
  17.          include  "exec/types.i"
  18.          include  "exec/funcdef.i"
  19.          include  "exec/exec_lib.i"
  20.  
  21.          include  "libraries/dos.i"
  22.          include  "libraries/dos_lib.i"
  23.  
  24.          include  "devices/serial.i"
  25.          include  "devices/narrator.i"
  26.  
  27. *                    Program History:
  28. *                   ------------------
  29.  
  30. * (Once Upon A Time...) This prog was written on a boring day in January.
  31.  
  32. * During February, I decided that it should have been completed in January!!
  33. * (But It wasn't!).   A Guilt complex set in, but a rare disease known as
  34. * 'PAID WORK' caused me to spend my time trying to complete my arcade game
  35. * for BT RAINBIRD, called "STARGLIDER"  (a 3d space battle simulator)
  36.  
  37. * Pressure from CBM Sysops on PLINK (thanks Harv!) made me add the final
  38. * tweaks, and.. (suspense.....) Here it is, the first talking terminal!
  39.  
  40. * Disclaimers:
  41.  
  42. * I haven't read the Intuition manual yet, and thus there isn't a friendly
  43. * user-interface in this program (.. yet!)  I will add it... eventually.
  44.  
  45. * PLEASE, People!! Improve this program!!  Ensure that it is in the
  46. * Public domain, but feel free to add lotsa fun features to this 'frill
  47. * free' Terminal program.
  48.  
  49. * Above all, this program was an exercise for me to learn about Amiga's OS
  50. * and how to use it.  Unfortunately, machine code usage of Amiga OS is
  51. * very poorly documented... All the manuals assume a working knowledge
  52. * of 'C', but unfortunately (for me) I have not learned this language.
  53.  
  54. *  I had fun writing this; hope You enjoy using it.
  55.  
  56. *                    ---  Jez San,
  57. *
  58. *                      London, England.
  59.  
  60. * Tracking me down...
  61. * In USA -> CIS '72247,3661', BIX 'jsan', PLINK 'UK JEZ', Source 'BCD776',
  62. * In UK -> Prestel, '919991062', MUD 'Jez'.
  63.  
  64.  
  65. * -------------------------------------------------------------- *
  66.  
  67.  
  68.  
  69. *  A Macro, cos I'm lazy at typing...
  70.  
  71. print    macro    * handle,messagepointer
  72.          move.l   \1,d1
  73.          lea      \2(PC),a0
  74.          bsr      message
  75.          endm
  76.  
  77.  
  78.  
  79. * Arbitrary Equates, and his pal; Label Definitions
  80.  
  81. sysbase  equ      $4                Base Pointer to the Exec
  82. csi      equ      $9b               Control Sequence Introducer
  83. keytime  equ      500               us timeout
  84. myflags  equ      SERF_SHARED+SERF_XDISABLED+SERF_RAD_BOOGIE
  85.  
  86. * Popular Character Definitions
  87.  
  88. lf       equ      $a                Our Old Favourites!
  89. cr       equ      $d
  90. xon      equ      $11               CtrlQ
  91. xoff     equ      $13               CtrlS
  92. esc      equ      $1b
  93. space    equ      $20
  94.  
  95. * Xmodem Definitions
  96.  
  97. soh      equ      $01               Start Of Header
  98. eot      equ      $04               End Of Transmission
  99. ack      equ      $06               Acknowledge
  100. nak      equ      $15               No Acknowledge
  101. can      equ      $18               Cancel
  102.  
  103. _LVOTranslate  equ   -30            Undefined in my Library file! Hope your
  104. *                                   INCLUDE files are better than mine!
  105.  
  106.  
  107.  
  108. * .. And not forgetting The Program
  109.  
  110.  
  111. startup  move.l   sp,saveSP        Save the stack pointer, just in case
  112.          move.l   4(sp),d0         Size of our allocated Stack
  113.  
  114. * Point to our allocated memory (STACK! and bss)
  115.  
  116.          move.l   sp,a0             Current stack
  117.          sub.l    #endbss-startbss+256,d0
  118.          sub.l    d0,a0             Subtract our allowance to find start
  119.          sub.l    #256,d0           Subtract safety margin Length
  120.          and.w    #$ffff-3,d0       Mask to a Long Word boundary
  121.          move.l   a0,bufstart       Start of Buffer value
  122.          move.l   d0,buflen         Length of buffer value
  123.  
  124. * Open DOS library.
  125.  
  126.          move.l   sysbase,a6        Pointer to Exec Library
  127.          lea      thedos(pc),a1     Point to title of DOS
  128.          moveq    #0,d0             Version number
  129.          jsr      _LVOOpenLibrary(a6)
  130.          move.l   d0,dosbase        DOS library Pointer
  131.          beq      openerr           Error, can't open library!
  132.  
  133. * Open Translator library.
  134.  
  135.          lea      thetrans(pc),a1   Point to title of Translator
  136.          moveq    #0,d0             Version
  137.          jsr      _LVOOpenLibrary(a6)
  138.          move.l   d0,tranbase
  139.          beq      openerr
  140.  
  141.  
  142. * Open Console for I/O.
  143.  
  144.          lea      conname(pc),a1    Point to console definition text
  145.          bsr      openfile          Open a DOS file
  146.          beq      openerr
  147.          move.l   d0,chandle        Console Handle
  148.  
  149. * Find what task we are in, and install it in the msg ports
  150.  
  151.          sub.l    a1,a1             We want *MY* task
  152.          move.l   sysbase,a6        Exec Lib Ptr
  153.          jsr      _LVOFindTask(a6)
  154.  
  155.          move.l   d0,MP_SIGTASK+write_reply
  156.          move.l   d0,MP_SIGTASK+read_reply
  157.          move.l   d0,MP_SIGTASK+nwriterep
  158.  
  159. * Add three Message Ports to the system, one for Input, one for Output,
  160. * and one for Narrator.
  161.  
  162.          lea      read_reply,a1     Message Port
  163.          jsr      _LVOAddPort(a6)   Add another Port to list
  164.  
  165.          lea      write_reply,a1    Repeat procedure for another Port
  166.          jsr      _LVOAddPort(a6)
  167.  
  168.          lea      nwriterep,a1      Add the Narrator message port
  169.          jsr      _LVOAddPort(a6)
  170.  
  171.  
  172. * Open Serial.Device for Input
  173.  
  174.          lea      readreq,a1              IRequest area
  175.          move.b   #myflags,IO_SERFLAGS(a1)
  176.          move.l   #read_reply,$E(a1)      !!! Message.MN_REPLYPORT undefined
  177.  
  178.          moveq    #0,d0                   UnitNumber, ignored.
  179.          moveq    #0,d1                   Flags, ignored.
  180.          lea      serdevice(pc),a0        Point to the Device Name
  181.  
  182.          jsr      _LVOOpenDevice(a6)      Open it
  183.          tst.l    d0                      Did it Open Okay?
  184.          bne      openerr                 Zero is Successful (consistent!!?)
  185.  
  186. * Open Serial.Device for Output
  187.  
  188.          lea      writereq,a1             ORequest area
  189.          move.b   #myflags,IO_SERFLAGS(a1)
  190.          move.l   #write_reply,$E(a1)     Message.NN_REPLYPORT
  191.  
  192.          moveq    #0,d0
  193.          moveq    #0,d1
  194.          lea      serdevice(pc),a0        Device definition
  195.  
  196.          jsr      _LVOOpenDevice(a6)
  197.          tst.l    d0
  198.          bne      openerr
  199.  
  200. * Open Narrator device.
  201.  
  202.          lea      talkio,a1               Talk request block
  203.          moveq    #0,d0                   Unit Number=0
  204.          moveq    #0,d1                   Device number=0
  205.          lea      nardevice(pc),a0        Device definition
  206.  
  207.          jsr      _LVOOpenDevice(a6)
  208.          tst.l    d0
  209.          bne      openerr
  210.  
  211. * Initialise the Narrator
  212.  
  213.          lea      talkio,a1               Talk Output request area
  214.          move.l   #nwriterep,$E(a1)       Find the message port!
  215.          move.l   #amaps,NDI_CHMASKS(a1)  Audio Channel Masks
  216.          move.w   #4,NDI_NUMMASKS(a1)     Number of channels
  217.          move.w   #210,NDI_RATE(a1)       Make it talk faster than average!
  218.  
  219. * Initialise the serial port here...
  220.  
  221.          lea      writereq,a1             Point to request block
  222.          move.b   #8,IO_READLEN(a1)
  223.          move.b   #8,IO_WRITELEN(a1)
  224.          move.l   #0,IO_CTLCHAR(a1)       Should set to zero perhaps!?
  225.          move.b   #myflags,IO_SERFLAGS(a1)
  226.          move.w   #SDCMD_SETPARAMS,IO_COMMAND(a1)
  227.  
  228.          move.l   sysbase,a6
  229.          jsr      _LVODoIO(a6)            Send it!
  230.  
  231.          bsr      initser
  232.  
  233.          print    chandle,welcome         Display the welcome Message
  234.  
  235. * Initialise a few variables
  236.  
  237.          st       squalking         Turn squalking off as default
  238.          clr.b    fileflag          No file Transfer going on
  239.          move.l   bufstart,bufptr   Buffer Empty
  240.          clr.b    duplex            Default = Full Duplex
  241.          clr.l    lengthin          No text in speech buffer
  242.          move.l   #intext,textptr   Initial buffer pointer
  243.  
  244.  
  245.  
  246. * The Main loop!
  247.  
  248. mainloop bsr      scankey           User type a key?
  249.          beq      notkeyu           Nope
  250.  
  251.          cmp.b    #csi,d0           Did User press a function key?
  252.          beq      trycsi            Yes, so print up the menu
  253.  
  254. * -- Decode Function Keys here, if necessary!  --
  255.  
  256.          tst.b    duplex            Full or Half Duplex?
  257.          beq.s    fulldup           Z=Full Duplex
  258.          bsr      wrchar            Local echo
  259. fulldup  bsr      sendser           Send the character
  260. notkeyu  move.b   fileflag,d0       Are we Uploading the Buffer?
  261.          cmp.b    #'U',d0           Yes??
  262.          bne.s    notkey1           Nope!
  263.  
  264.          move.l   ubufptr,a0        Get Upload pointer
  265.          move.l   bufptr,a1         Get Normal Buffer Pointer
  266.          cmp.l    a1,a0             How are we doing?
  267.          bge.s    finupl            Must have finished!
  268.          move.b   (a0)+,d1          Get next character to Upload
  269.          move.l   a0,ubufptr        Increment Upload buffer pointer
  270.          bsr      sendser           Send the character
  271.          bra.s    notkey1           ... and continue
  272. finupl   clr.b    fileflag          Discontinue the Upload sequence
  273. notkey1  bsr      scanser           Any chars waiting on the Ser port?
  274.          bmi.s    mainloop          Nope, nothing there!
  275.          and.w    #$7f,d0           Mask out Parity bit (Ignore Parity!)
  276.          bsr      wrchar            Print it on the screen
  277.  
  278.          cmp.l    #255,lengthin     If buffer full, dont buffer anymore
  279.          beq      dosqualk
  280.          move.l   textptr,a0        Put character into Text buffer
  281.          move.b   d0,(a0)+          ready for speech
  282.          move.l   a0,textptr
  283.          addq.l   #1,lengthin
  284.  
  285.          cmp.b    #cr,d0            Was it end of line?
  286.          bne.s    nsqualk1          If so, Squalk it!
  287. dosqualk bsr      squalk
  288.  
  289. nsqualk1 cmp.b    #'D',fileflag     Are we downloading text?
  290.          bne      mainloop          Nope!
  291.  
  292.          move.l   bufptr,a0         We ARE downloading, so Where Buffer?
  293.          move.b   d0,(a0)+          Insert Character into Buffer
  294.          move.l   a0,bufptr         Increment buffer
  295.  
  296. * Test for Buffer Overflow?    Not properly implemented yet!
  297.          move.l   a0,a1
  298.          sub.l    bufstart,a1       current-start = Length
  299.          cmp.l    buflen,a1         Is it too big?
  300.          bcc      warnsave          Force user to Save Buffer if too big!
  301.  
  302.          bra      mainloop          .. And continue for more!
  303.  
  304. * User pressed a Special key, generating a Control Sequence Introducer
  305.  
  306. trycsi   bsr      rdchar            Get the next character
  307.          cmp.b    #'?',d0           Was it HELP?
  308.          bne.s    morecsi
  309.  
  310.          bsr      rdchar            Get next char
  311.          cmp.b    #'~',d0           Caret is end of sequence
  312.          beq      trymenu
  313.          bra      mainloop
  314.  
  315. morecsi  bra      mainloop          Test for Function Keys here!
  316.  
  317.  
  318. * User pressed HELP key, to display the menu
  319.  
  320. trymenu  bsr      sendxoff
  321.  
  322. * Open a new window stacked on top of the old one, for displaying
  323. * the Menu.
  324.  
  325.          lea      conname(pc),a1    Point to console definition text
  326.          bsr      openfile          Open it
  327.          beq      openerr
  328.          move.l   d0,mhandle        Console Window's handle
  329.  
  330. * Display the menu!
  331.  
  332. menuagn  print    mhandle,menutext  Display the menu
  333.  
  334.          bsr      infobuf           How many characters in buffer?
  335.  
  336. menuagn2 bsr      rdmenu            Get a key from Menu Console
  337.  
  338.          cmp.b    #esc,d0           Escape key pressed?
  339.          beq      menuexit          So Return back to Terminal
  340.  
  341.          and.w    #$df,d0           Mask out Lower Case
  342.          cmp.b    #'Q',d0           Q for Quit?
  343.          beq      termmenu
  344.          cmp.b    #'B',d0           B for Baudrate?
  345.          beq      setbaud
  346.          cmp.b    #'C',d0           C for Clear?
  347.          beq      doclear
  348.          cmp.b    #'D',d0           D for Download?
  349.          beq      dodownl
  350.          cmp.b    #'E',d0           E for Echo?
  351.          beq      localec
  352.          cmp.b    #'L',d0           L for Load Buffer?
  353.          beq      loadbuf
  354.          cmp.b    #'U',d0           U for Upload Buffer?
  355.          beq      uplode
  356.          cmp.b    #'X',d0           X for Xmodem Transfer?
  357.          beq      xmodem
  358.          cmp.b    #'T',d0           T for Talk mode?
  359.          beq      talkmode
  360.  
  361.          bra      menuagn2          Go back for another choice perhaps?
  362.  
  363. menuexit bsr.s    closemenu         Close the menu console
  364.          bsr      sendxon           Send an Xon to resmue host xmission
  365.  
  366.          bra      mainloop          Now back to the Terminal!
  367.  
  368. termmenu bsr.s    closemenu         Close the Menu console
  369.          bra      terminate         Quit the program!
  370.  
  371.  
  372. * Close the Menu Console window
  373.  
  374. closemenu
  375.          move.l   mhandle,d1        Close the Menu window
  376.          move.l   dosbase,a6        Dos library
  377.          jmp      _LVOClose(a6)
  378.  
  379.  
  380. * Clear the Capture Buffer
  381.  
  382. clear    move.l   bufstart,bufptr
  383.          bra      trymenu
  384.  
  385.  
  386. * Change the baud rate
  387.  
  388.  
  389. * Clear the buffer
  390.  
  391. doclear  move.l   bufstart,bufptr
  392.          bra      menuagn
  393.  
  394. * Start the Download in process
  395.  
  396. dodownl  move.b   fileflag,d0       Are we already downloading?
  397.          cmp.b    #'D',d0           Yes??
  398.          beq.s    down2             if so, stop downloading, and save buf!
  399.  
  400. * Print up a message saying that downloading is ON!  and do it!
  401.  
  402.          print    mhandle,down1m
  403.  
  404.          move.b   #'D',fileflag        Flag saying Download is on!
  405.          move.l   bufstart,bufptr      Clear buffer contents!
  406.  
  407.          bra      menuagn              Go back to Main Loop
  408.  
  409. * Downloading must be turned OFF here, and buffer saved.
  410.  
  411. down2    move.l   bufptr,a0            Was there anything in the buffer?
  412.          cmp.l    bufstart,a0          Yes?
  413.          beq      down3                Turn off downloader, anyway!
  414.  
  415.          bsr      savebuf              Save the buffer
  416.          bne      menuagn
  417.  
  418. down3    clr.b    fileflag             Stop Downloading,
  419.          move.l   bufstart,bufptr      and clear buffer
  420.  
  421.          print    mhandle,down2m       Tell user that Download is OFF
  422.  
  423.          bra      menuagn              Go back to Main Loop
  424.  
  425. * Toggle the Local Echo mode
  426.  
  427. localec  print    mhandle,nowset2m
  428.  
  429.          not.b    duplex               Invert state
  430.          beq.s    showfull
  431.  
  432. * Half duplex...
  433.  
  434.          print    mhandle,halfm
  435.          bra      menuagn
  436.  
  437. * Full duplex...
  438.  
  439. showfull print    mhandle,fullm
  440.          bra      menuagn              Back to the Menu
  441.  
  442.  
  443. talkmode not.b    squalking
  444.          beq.s    issqualk
  445.  
  446.          print    mhandle,notsqm
  447.          bra      menuagn
  448.  
  449. issqualk print    mhandle,yessqm
  450.          bra      menuagn
  451.  
  452.  
  453. * Start an Upload
  454.  
  455. uplode   move.b   fileflag,d0          Are we already uploading?
  456.          cmp.b    #'U',d0              Yes??
  457.          beq      alredu               tell'em we already are!
  458.  
  459.          move.l   bufptr,a0            Anything in buffer?
  460.          move.l   bufstart,a1          Start of buffer
  461.          cmp.l    a0,a1                forget it if nothing in buffer
  462.          beq      exitu1
  463.  
  464.          move.b   #'U',fileflag        Flag an Uplo0ad in progress
  465.          move.l   a0,ubufptr           Point the Upload buffer to text.
  466.  
  467.          print    mhandle,upld1m       Tell user that Upload has started
  468.  
  469. exitu1   bra      menuagn              Go back to Main Loop
  470.  
  471. * Tell the User they are very naughty indeed!
  472.  
  473. alredu   print    mhandle,upld2m
  474.  
  475.          bra      menuagn              Back to Menu time!
  476.  
  477.  
  478. * Display how many characters in Buffer
  479.  
  480. infobuf  move.l   bufptr,d0         Current buffer pointer - start = length
  481.          sub.l    bufstart,d0
  482.          bsr      bin2decl
  483.  
  484.          print    mhandle,infmess1
  485.  
  486.          move.l   buflen,d0
  487.          bsr      bin2decl
  488.  
  489.          print    mhandle,infmess2
  490.          rts
  491.  
  492.  
  493. warnsave print    chandle,warnmes
  494.          bsr      rdchar
  495.          bra      trymenu
  496.  
  497.  
  498. * Save the Buffer out to disk and Clear it.
  499.  
  500. savebuf  bsr      filename
  501.          beq      badsave
  502.  
  503.          bsr      openup
  504.          beq      badsave
  505.          bsr      writefile
  506.          bsr      closefile
  507.          moveq    #0,d0          Signal an OKAY save.
  508.          rts
  509.  
  510.  
  511. * Load Buffer from disk
  512.  
  513. loadbuf  bsr      filename
  514.          beq      badload
  515.  
  516. * Zero out entire buffer area prior to loading a flie
  517.          move.l   bufstart,a0
  518.          move.l   buflen,d0
  519.          lsr.l    #2,d0
  520.  
  521. bufclrlp clr.l    (a0)+
  522.          subq.l   #1,d0
  523.          bne.s    bufclrlp
  524.  
  525.  
  526.          bsr      openit
  527.          beq      badload
  528.  
  529.          bsr      readfile
  530.          bsr      closefile
  531.  
  532.          bra      menuagn
  533.  
  534. badload  print    mhandle,bloadmes
  535.          bra      menuagn
  536.  
  537. badsave  print    mhandle,bsavemes
  538.          moveq    #-1,d0
  539.          rts
  540.  
  541.  
  542. * Requests a filename
  543.  
  544. filename print    mhandle,filemes
  545.          bsr      getline         Get a line of text
  546.  
  547. * Copy over filename from input buffer to file buffer
  548.  
  549.          lea      inputbuf,a2
  550.          lea      filehead,a3
  551.          moveq    #32,d2
  552. copylp1  move.b   (a2)+,(a3)+
  553.          dbra     d2,copylp1
  554.  
  555.          move.b   #13,d0
  556.          bsr      wrmenu
  557.          move.b   #10,d0
  558.          bsr      wrmenu
  559.  
  560.          tst.b    inputbuf       Will be zero if no entry
  561.  
  562.          rts
  563.  
  564. * Gets a line of text from the user
  565.  
  566. getline  lea      inputbuf,a2
  567.          clr.l    (a2)           Zero the first bit
  568.  
  569. getlin1  bsr      rdmenu         Get keyboard Input
  570.          cmp.b    #8,d0          Backspace
  571.          beq      backspace
  572.          cmp.b    #127,d0        Delete
  573.          beq      backspace
  574.          bsr      wrmenu         Display it onscreen
  575.          cmp.b    #13,d0         Return?
  576.          beq      creturn
  577.          move.b   d0,(a2)+       Put character into buffer
  578.          bra      getlin1
  579.  
  580.  
  581. * Return pressed... put a Null to terminate, and exit with d0=num of chars.
  582. creturn  clr.b    (a2)+
  583.          sub.l    #inputbuf,a2
  584.          move.l   a2,d0
  585.          rts
  586.  
  587. backspace
  588.          cmp.l    #inputbuf,a2   Dont allow backspacing before the Start
  589.          beq      getlin1
  590.          move.b   #8,d0          Space
  591.          bsr      wrmenu
  592.          move.b   #32,d0         Space
  593.          bsr      wrmenu
  594.          move.b   #8,d0          Backspace
  595.          bsr      wrmenu
  596.          clr.b    (a2)           Zero the current character
  597.          subq.l   #1,a2          Backtrack one character
  598.          bra      getlin1
  599.  
  600. * Read in an entire file
  601.  
  602. readfile move.l   fhandle,d1           Handle of the flie
  603.  
  604.          move.l   bufstart,d2          Where to put the data
  605.          move.l   buflen,d3            Length
  606.          move.l   dosbase,a6           Library ptr
  607.          jsr      _LVORead(a6)         Get the text from the file
  608.  
  609. * Update length of file to represent amount of text read
  610.  
  611.          move.l   bufstart,d1          Get start of buffer
  612.          add.l    d0,d1                Add number of characters in file
  613.          move.l   d1,bufptr            Save result as End of buffer
  614.  
  615.          rts
  616.  
  617. * Write out an entire file
  618.  
  619. writefile move.l  fhandle,d1           Handle of File
  620.  
  621.          move.l   bufstart,d2          Start of Buffer
  622.          move.l   bufptr,d3            length = End of Buffer
  623.          sub.l    bufstart,d3          Subtract Start of buffer = Length
  624.          move.l   dosbase,a6           Library ptr
  625.          jmp      _LVOWrite(a6)        Write the text to the console window
  626.  
  627. * Close the file
  628.  
  629. closefile move.l   fhandle,d1       Close the Menu window
  630.          move.l   dosbase,a6        Dos library
  631.          jmp      _LVOClose(a6)
  632.  
  633. * Open the file
  634.  
  635. openit   lea      filehead,a1
  636.          bsr      openfile
  637.          move.l   d0,fhandle
  638.          tst.l    d0
  639.          rts
  640.  
  641. * Open file for updating
  642.  
  643. openup   lea      filehead,a1
  644.          bsr      openwrite
  645.          move.l   d0,fhandle
  646.          tst.l    d0
  647.          rts
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654. * Flush Serial Port, to ensure internal buffer is M.T.
  655.  
  656. flushser bsr      scanser        Try and get some characters from port
  657.          bpl.s    flushser       If we get some, it aint M.T.
  658.          rts
  659.  
  660. * Xmodem file transfer bits
  661.  
  662. xmodem   print    mhandle,xmes1
  663.  
  664.          bsr      rdmenu
  665.          and.w    #$df,d0
  666.          cmp.b    #'U',d0
  667.          beq      xmodemup
  668.          cmp.b    #'D',d0
  669.          beq      xmodemdn
  670.  
  671.          bra      menuagn
  672.  
  673. xmodemup print    mhandle,exitmess
  674.  
  675.          bsr      sendxon           Get host transmitting again
  676.  
  677.          move.l   bufstart,a4       Start of Xmodem buffer
  678.          moveq    #1,d2             Block number
  679.  
  680. * Start by waiting for an initial NAK from the receive side
  681.  
  682. xmodeup0 print    mhandle,upmes1
  683.  
  684.          move.w   #20,d6            Timeout
  685.          bsr      waitser
  686.          bmi.s    xsendblk
  687.          cmp.b    #nak,d0
  688.          bne.s    xmodeup0
  689.  
  690. * Check for End of file here
  691.  
  692. xsendblk move.b   d2,block
  693.          bsr      scanmenu       Does User want to cancel?
  694.          bne      xcancel
  695.          move.b   block,d2
  696.  
  697.          move.l   bufptr,a0      Are we at end of buffer?
  698.          cmp.l    a4,a0
  699.          ble      finxup
  700.  
  701.          bsr      prblock
  702.          clr.b    d3             Checksum
  703.  
  704.          move.b   #soh,d0        Start of block
  705.          bsr      sendser
  706.  
  707.          move.b   d2,d0
  708.          bsr      sendser        Block number
  709.          move.b   d2,d0
  710.          not.b    d0
  711.          bsr      sendser
  712.  
  713.          move.w   #127,d4        Counter for block
  714. xmodeulp move.b   (a4)+,d0       Get a byte
  715.          add.b    d0,d3          Compute checksum
  716.          bsr      sendser
  717.          dbra     d4,xmodeulp
  718.  
  719.          move.b   d3,d0       Send checksum
  720.          bsr      sendser
  721.  
  722. wait20s  move.w   #20,d6         Wait 20 seconds
  723.          bsr      waitser
  724.          bmi.s    upnogood
  725.  
  726.          cmp.b    #ack,d0
  727.          beq.s    upgonext
  728.          cmp.b    #can,d0
  729.          beq.s    xcancel
  730.  
  731.          cmp.b    #nak,d0
  732.          bne.s    wait20s
  733.  
  734. upnogood print    mhandle,uperr1
  735.  
  736. uretry   sub.l    #128,a4        Backtrack a block
  737.          bra      xsendblk
  738.  
  739. upgonext addq.b   #1,d2              Increase block number
  740.          bra      xsendblk
  741.  
  742. finxup   move.b   #eot,d0
  743.          bsr      sendser
  744.  
  745. finxup1  move.w   #20,d6
  746.          bsr      waitser
  747.          bmi.s    finxup
  748.          cmp.b    #ack,d0
  749.          beq.s    finxup2
  750.          bra.s    finxup1
  751.  
  752. finxup2  print    mhandle,updun1
  753.  
  754.          bra      menuagn
  755.  
  756. xcancel  print    mhandle,cancmes
  757.          bsr      rdmenu
  758.          bsr      nlmenu
  759.          and.w    #$df,d0
  760.          cmp.b    #'Y',d0
  761.          beq      uretry
  762.          move.b   #can,d0
  763.          bsr      sendser
  764.          bra      menuagn
  765.  
  766. nlmenu   move.l   d0,-(sp)
  767.          move.b   #13,d0
  768.          bsr      wrmenu
  769.          move.b   #10,d0
  770.          bsr      wrmenu
  771.          move.l   (sp)+,d0
  772.          rts
  773.  
  774. xrcancel print    mhandle,cancmes
  775.  
  776.          bsr      rdmenu
  777.          bsr      nlmenu
  778.          and.w    #$df,d0
  779.          cmp.b    #'Y',d0
  780.          beq      xreclp0
  781.          move.b   #can,d0
  782.          bsr      sendser
  783.          bra      menuagn
  784.  
  785.  
  786. xmodemdn print    mhandle,exitmess
  787.  
  788.          bsr      sendxon           Get host moving again
  789.  
  790.          move.l   bufstart,a4
  791.          moveq    #1,d2
  792.  
  793.          print    mhandle,rstart1
  794.  
  795. * Send initial NAK
  796. xreclp0  bsr      sendnak
  797.  
  798. xreclp1a bsr      scanmenu          Has user pressed a key?
  799.          bne      xrcancel
  800.  
  801.          move.w   #20,d6            Wait for block
  802.          bsr      waitser
  803.          bpl.s    xrecok1           Keep doing it, if nothing going.
  804.  
  805.          print    mhandle,ret1mes
  806.          bra.s    xreclp0
  807.  
  808. xrecok1  cmp.b    #soh,d0
  809.          beq.s    xrecrcv
  810.          cmp.b    #eot,d0
  811.          beq      xreceot
  812.          cmp.b    #can,d0
  813.          beq      xrcancel
  814.  
  815.          bra.s    xreclp1a
  816.  
  817. * Block coming in...
  818. xrecrcv   bsr      prblock
  819.  
  820.          bsr      wait10            Get block
  821.          bmi      xrslowr
  822.  
  823.          cmp.b    d0,d2             Same as current one?
  824.          bne      xrbadblk
  825.  
  826.          bsr      wait10            Get inversed block number
  827.          bmi      xrslowr
  828.  
  829.          not.b    d0
  830.          cmp.b    d0,d2             Okay?
  831.          bne      xrbadbl2          Definitely a bad block
  832.  
  833. * Get the 128 data bytes
  834.  
  835.          move.w   #127,d4           Byte count
  836.          clr.b    d3                Checksum
  837.  
  838. xrecrclp bsr      wait10            Timeout
  839.          bmi.s    xrecnop3
  840.          move.b   d0,(a4)+          Store the character
  841.          add.b    d0,d3             Checksum
  842.          dbra     d4,xrecrclp       Loop for more
  843.  
  844.          bsr      wait10
  845.          bmi.s    xrcheckm
  846.          cmp.b    d0,d3             Checksum any good?
  847.          bne      xrchecks
  848.  
  849. * Block was Okay, so increment block counter
  850.          addq.b   #1,d2             Increment block counter, and continue
  851.          bsr      sendack
  852.          bra      xreclp1a
  853.  
  854. * A character was missed from inside a block
  855. xrecnop3 print    mhandle,misschm
  856.          ext.l    d4
  857.          add.w    d4,a4
  858.          sub.w    #127,a4
  859.  
  860.          bsr      waitfin
  861.          bra      xreclp0
  862.  
  863. * Missed checksum
  864. xrcheckm print    mhandle,xchksm2
  865.          bsr      waitfin
  866.          bra      xreclp0
  867.  
  868. xrchecks sub.l    #128,a4
  869.          move.l   d0,-(sp)
  870.          print    mhandle,xchksm
  871.          move.b   d3,d0
  872.          and.w    #$ff,d0
  873.          bsr      bin2decw
  874.          print    mhandle,xchksm1
  875.          move.l   (sp)+,d0
  876.          and.w    #$ff,d0
  877.          bsr      bin2decw
  878.          bsr      nlmenu
  879.  
  880.          bsr      waitfin
  881.          bra      xreclp0
  882.  
  883. xrslowr  print    mhandle,slowm1
  884.          bsr      waitfin
  885.          bra      xreclp0
  886.  
  887. xrbadblk addq.b   #1,d0
  888.          cmp.b    d0,d2
  889.          beq.s    xrbbb1
  890.          subq.b   #1,d0
  891.  
  892. xrbadbl2 move.l   d0,-(sp)
  893.          print    mhandle,badblkm
  894.          move.l   (sp)+,d0
  895.          and.w    #$ff,d0
  896.          bsr      bin2decw
  897.          bsr      nlmenu
  898.          bsr      waitfin
  899.          bra      xreclp0
  900.  
  901. * If previous block was repeated, then do an ACK to get it up to date
  902. xrbbb1   bsr      waitfin
  903.          bsr      sendack
  904.          print    mhandle,dupmes1
  905.          bra      xreclp1a
  906.  
  907. xreceot  bsr      sendack
  908.  
  909.          move.l   a4,bufptr         Update buffer size
  910.  
  911.          print    mhandle,xrecm2
  912.  
  913. * File downloaded, so now determine the ACCURATE length of file.
  914.  
  915.          bsr      rdmenu
  916.          and.w    #$df,d0
  917.          cmp.b    #'Y',d0
  918.          bne      savedown
  919.  
  920. * Chop the file here...
  921.  
  922.          print    mhandle,xrecm3
  923.  
  924.          move.l   bufptr,d0         Current file's length
  925.  ` ;     sub.l    bufstart,d0
  926.          bsr      bin2decl
  927.  
  928.          print    mhandle,xrecm4
  929.  
  930. * Determine approximate length...
  931.  
  932.          move.l   bufptr,a0         Last byte=Null?
  933.          move.b   -(a0),d1
  934.  
  935. detlp1   cmp.b    -(a0),d1          Is the previous byte the same?
  936.          beq.s    detlp1
  937.  
  938.          addq.l   #1,a0             Forward one character again
  939.  
  940.          sub.l    bufstart,a0       Turn it into a Length
  941.          move.l   a0,d0
  942.  
  943.          bsr      bin2decl          Print it
  944.          bsr      nlmenu
  945.  
  946. * Perform decimal input value here and change bufptr accordingly!
  947.  
  948.          print    mhandle,askchop
  949.          bsr      getline
  950.          tst.l    d0
  951.          beq      savedown
  952.  
  953.          lea      inputbuf,a0
  954.          bsr      dec2bin
  955.  
  956.          tst.l    d0
  957.          beq      savedown
  958.          bmi      savedown
  959.  
  960. * Really ought to check that the CHOP value is within range here!!
  961.  
  962.          add.l    bufstart,d0
  963.          move.l   d0,bufptr
  964.  
  965. savedown bsr      savebuf
  966.          bra      menuagn
  967.  
  968. * Wait for ONE total second of nothingness!
  969.  
  970. waitfin  move.w   #2,d6
  971.          bsr      waitser
  972.          bpl.s    waitfin
  973.          rts
  974.  
  975.  
  976. * Print the current block number
  977. prblock  movem.l  d0-d7/a0-a6,-(sp)
  978.          print    mhandle,pblokm
  979.          clr.l    d0
  980.          move.b   d2,d0
  981.          bsr      bin2decw
  982.          move.b   #32,d0
  983.          bsr      wrmenu
  984.          bsr      wrmenu
  985.          bsr      wrmenu
  986.          move.b   #13,d0
  987.          bsr      wrmenu
  988.          movem.l  (sp)+,d0-d7/a0-a6
  989.          rts
  990.  
  991.  
  992. * Waits ten seconds for a character then gives up
  993.  
  994. wait10   move.w   #10,d6
  995.  
  996. * Scan for a character with wait for d6 number of seconds
  997.  
  998. waitser  bsr      scanser
  999.          bpl.s    retwait1
  1000.  
  1001.          subq.w   #1,d6
  1002. waitser1 move.w   #17000,d7
  1003. waitser2 bsr      scanser
  1004.          bpl.s    retwait1
  1005.          dbra     d7,waitser2
  1006.          dbra     d6,waitser1
  1007.          moveq    #-1,d0         Necessary?
  1008. retwait1 tst.l    d0
  1009.          rts
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016. * Terminate this program and return to CLI
  1017.  
  1018. terminate
  1019.          lea      read_reply,a1  Remove the Reply Port
  1020.          move.l   sysbase,a6     Exec Lib Ptr
  1021.          jsr      _LVORemPort(a6)
  1022.  
  1023.          lea      write_reply,a1 Remove this one too
  1024.          jsr      _LVORemPort(a6)
  1025.  
  1026.          lea      nwriterep,a1   Remove Narrator port
  1027.          jsr      _LVORemPort(a6)
  1028.  
  1029.          lea      readreq,a1     Close the Serial Device
  1030.          jsr      _LVOCloseDevice(a6)
  1031.  
  1032.          lea      writereq,a1    Again
  1033.          jsr      _LVOCloseDevice(a6)
  1034.  
  1035.          lea      talkio,a1      Narrator Device
  1036.          jsr      _LVOCloseDevice(a6)
  1037.  
  1038.  
  1039.          move.l   chandle,d1     Close Console window for final time
  1040.          move.l   dosbase,a6
  1041.          jsr      _LVOClose(a6)
  1042.  
  1043.          move.l   tranbase,a1    Close the translator library
  1044.          move.l   sysbase,a6
  1045.          jsr      _LVOCloseLibrary(a6)
  1046.  
  1047.          move.l   dosbase,a1     Close the DOS library
  1048.          jsr      _LVOCloseLibrary(a6)
  1049.  
  1050.          moveq    #0,d1          Return Code=Good
  1051.          move.l   d1,d0
  1052.  
  1053. exitprog move.l   saveSP,sp      Restore Old Stack Pointer
  1054.          rts                     Yea, a JMP would have sufficed!
  1055.  
  1056. * Dos command to open a file
  1057.  
  1058. openfile move.l   a1,d1             Wants it in Data register (weird!)
  1059.          move.l   #MODE_OLDFILE,d2  Signal not to create a new file
  1060.          move.l   dosbase,a6        Dos lib
  1061.          jsr      _LVOOpen(a6)      Open the file
  1062.          tst.l    d0                An Error perhaps?
  1063.          rts                        File's handle in d0
  1064.  
  1065. * Opens a file for writing!
  1066. openwrite
  1067.          move.l   a1,d1
  1068.          move.l   #MODE_NEWFILE,d2
  1069.          move.l   dosbase,a6
  1070.          jsr      _LVOOpen(a6)
  1071.          tst.l    d0
  1072.          rts
  1073.  
  1074.  
  1075. * Signal an error because something didn't Open properly!
  1076.  
  1077. *openerr move.l   chandle,d1     Close Console window for final time
  1078.          move.l   dosbase,a6
  1079.          jsr      _LVOClose(a6)
  1080. openerr
  1081.          move.l   dosbase,a1     Close the DOS library
  1082.          move.l   sysbase,a6
  1083.          jsr      _LVOCloseLibrary(a6)
  1084.  
  1085.          moveq    #-1,d1         Return code = BAD!
  1086.          move.l   d1,d0
  1087.  
  1088.          bra      exitprog
  1089.  
  1090.  
  1091. * Prints the message pointed to by a0, (Null terminated).
  1092.  
  1093. message  movem.l  d0-d3,-(sp)
  1094.          move.l   a0,d2                Start of message
  1095.          clr.l    d3                   Length is zero for the moment
  1096. message1 tst.b    (a0)+                End of message?
  1097.          beq.s    message2             Length known, go print it now!
  1098.          addq.l   #1,d3                Increment Length
  1099.          bra.s    message1             Back for more characters
  1100.  
  1101. * Ready to print message now: d1=dest handle, d2=ptr to text, d3=length.
  1102.  
  1103. message2 move.l   dosbase,a6           Library ptr
  1104.          jsr      _LVOWrite(a6)        Write the text to the console window
  1105.          movem.l  (sp)+,d0-d3
  1106.          rts
  1107.  
  1108. wrmenu   movem.l  d0-d7/a0-a6,-(sp)
  1109.          move.l   mhandle,d1
  1110.          bra.s    chrout2
  1111.  
  1112. * Write character in d0 to Console Window
  1113.  
  1114. wrchar   movem.l  d0-d7/a0-a6,-(sp)    Save World!  (MOVEM overkill!??)
  1115.          move.l   chandle,d1           handle of Console window
  1116.  
  1117. chrout2  lea      cbuff,a1             Point to the character buffer
  1118.          move.b   d0,(a1)              Put character in buffer
  1119.          move.l   a1,d2                Weird data register usage
  1120.          move.l   #1,d3                Length
  1121.          move.l   dosbase,a6           Library ptr
  1122.          jsr      _LVOWrite(a6)        Write the text to the console window
  1123.  
  1124.          movem.l  (sp)+,d0-d7/a0-a6    Restore World
  1125.          rts
  1126.  
  1127. * Shortened special-case Serial characters
  1128.  
  1129. sendxon  move.b   #xon,d0           Send an Xon to resume data flow
  1130.          bra.s    sendser
  1131.  
  1132. sendxoff move.b   #xoff,d0          Send an Xoff to freeze data flow
  1133.          bra.s    sendser
  1134.  
  1135. sendack  move.b   #ack,d0           Send an ACK for acknowledgement of block
  1136.          bra.s    sendser
  1137.  
  1138. sendnak  move.b   #nak,d0           Send a NAK to indicate error of block
  1139.          bra.s    sendser
  1140.  
  1141. newline  move.b   #cr,d0            Print a NEWLINE
  1142.          bsr.s    wrchar
  1143.          move.b   #lf,d0            carriage return + line feed
  1144.          bra.s    wrchar
  1145.  
  1146. dospace  move.b   #space,d0         Print a Space
  1147.          bra.s    wrchar
  1148.  
  1149.  
  1150. * Serial Character Input
  1151. serin    movem.l  d1-d7/a0-a6,-(sp) Save World!
  1152.  
  1153. * Do a WaitIO to get the char, and followed by a SendIO to initiate the
  1154. * next read!
  1155.  
  1156.          lea      readreq,a1           Ptr to Request Block
  1157.          move.l   sysbase,a6           Exec lib ptr
  1158.          jsr      _LVOWaitIO(a6)
  1159.  
  1160.          clr.l    d0
  1161.          move.b   bufin,d0             The byte returned
  1162.        I[KW     $H20,-(sp)
  1163.  
  1164.          lea      readreq,a1           Request block
  1165.          move.l   #1,IO_LENGTH(a1)
  1166.          jsr      _LVOSendIO(a6)       Initiate the NEXT read
  1167.  
  1168.          move.l   (sp)+,d0
  1169.  
  1170.          movem.l  (sp)+,d1-d7/a0-a6    Restore World
  1171.          tst.l    d0                   Always Positive, so set PL flag
  1172.          rts
  1173.  
  1174. sendser  movem.l  d0-d7/a0-a6,-(sp)    Save World
  1175.  
  1176.          lea      writereq,a1          Ptr to Write Request block
  1177.          move.w   #CMD_WRITE,IO_COMMAND(a1)
  1178.          move.l   #1,IO_LENGTH(a1)     One byte
  1179.          move.l   #bufout,IO_DATA(a1)  Buffer address
  1180.  
  1181.          move.l   sysbase,a6           Exec Lib Ptr
  1182.          move.b   d0,bufout            Put byte and send it
  1183.  
  1184.          jsr      _LVODoIO(a6)         Send Byte
  1185.  
  1186.          movem.l  (sp)+,d0-d7/a0-a6    Restore World
  1187.          rts
  1188.  
  1189. * Read character into d0 from Console Window
  1190.  
  1191. rdchar   movem.l  d1-d7/a0-a6,-(sp)    Save World!
  1192.          move.l   chandle,d1           handle of Console window
  1193.          bra.s    chrin2
  1194.  
  1195. rdmenu   movem.l  d1-d7/a0-a6,-(sp)    Save World!
  1196.          move.l   mhandle,d1           Handle of Menu window
  1197.  
  1198. chrin2   lea      cbuff,a1
  1199.          move.l   a1,d2                Point to the character
  1200.          move.l   #1,d3                Length
  1201.          move.l   dosbase,a6           Library ptr
  1202.          jsr      _LVORead(a6)         Write the text to the console window
  1203.          clr.l    d0                   Prepare for receipt of a Char
  1204.          move.b   cbuff,d0             Character returned in d0
  1205.          movem.l  (sp)+,d1-d7/a0-a6    Restore World
  1206.          rts
  1207.  
  1208. * Scans for a key from the Keyboard, if nothing there, sets MINUS flag!
  1209. * Otherwise, character in d0
  1210.  
  1211. scanmenu movem.l  d1-d2,-(sp)
  1212.  
  1213.          move.l   mhandle,d1
  1214.          move.l   #keytime,d2
  1215.          move.l   dosbase,a6
  1216.          jsr      _LVOWaitForChar(a6)
  1217.  
  1218.          movem.l  (sp)+,d1-d2
  1219.  
  1220.          tst.l    d0
  1221.          beq.s    nokey1
  1222.  
  1223.          bra      rdmenu
  1224.  
  1225.  
  1226.  
  1227.  
  1228. scankey  move.l   chandle,d1           Console Handle
  1229.          move.l   #keytime,d2          Timeout
  1230.          move.l   dosbase,a6           Dos library
  1231.          jsr      _LVOWaitForChar(a6)  Anything waiting for us?
  1232.          tst.l    d0                   False=0
  1233.          beq.s    nokey1               Nothing there!
  1234.  
  1235.          bra.s    rdchar               Proceed further to Get it
  1236.  
  1237. nokey1   rts
  1238.  
  1239. scanser  lea      readreq,a1           Check to see if a character is there
  1240.          move.l   sysbase,a6           exec lib ptr
  1241.          jsr      _LVOCheckIO(a6)      Anything there?
  1242.          tst.l    d0                   Z=nothing
  1243.          bne      serin
  1244.  
  1245.          moveq    #-1,d0
  1246.          rts
  1247.  
  1248.  
  1249. * Text to speech of serial input
  1250.  
  1251. squalk   tst.b    squalking         Am I enabled?
  1252.          bne      endsqualk
  1253.  
  1254. * Send an XOFF to prevent host from sending anymore
  1255.          bsr      sendxoff
  1256.  
  1257. * Clear output buffer before use
  1258.  
  1259.          move.w   #127,d0
  1260.          lea      outtext,a0
  1261. sqclrlp  clr.l    (a0)+
  1262.          dbra     d0,sqclrlp
  1263.  
  1264. * Use Translator to convert input text into output phonemes
  1265.  
  1266.          lea      intext,a0
  1267.          move.l   lengthin,d0
  1268.  
  1269.          lea      outtext,a1
  1270.          move.l   #512,d1             Fixed length output buffer
  1271.                              
  1272.          move.l   tranbase,a6
  1273.          jsr      _LVOTranslate(a6)
  1274.  
  1275. * Use narrator to speak the phoneme text
  1276.  
  1277.          lea      talkio,a1            Narrator Request block
  1278.          move.w   #CMD_WRITE,IO_COMMAND(a1)
  1279.          move.l   #512,IO_LENGTH(a1)  Fixed length!
  1280.          move.l   #outtext,IO_DATA(a1)
  1281.  
  1282.          move.l   sysbase,a6
  1283.          jsr      _LVODoIO(a6)         Should be SendIO perhaps!?
  1284.  
  1285.          bsr      sendxon              Allow HOST to continue sending
  1286.  
  1287. endsqualk
  1288.          clr.l    lengthin             Reset the text buffers
  1289.          move.l   #intext,textptr
  1290.  
  1291.          rts
  1292.  
  1293.  
  1294. * Power of Ten table! (for binary/ascii routines!)
  1295.  
  1296. tentable dc.l     1
  1297.          dc.l     10
  1298.          dc.l     100
  1299.          dc.l     1000
  1300.          dc.l     10000
  1301. tenbckw  dc.l     100000
  1302.          dc.l     1000000
  1303.          dc.l     10000000
  1304.          dc.l     100000000
  1305. tenback  dc.l     1000000000
  1306.  
  1307.  
  1308.  
  1309. * Print a number that is contained in binary in d0
  1310. bin2decw movem.l  d0-d7/a0,-(sp)
  1311.          clr.w    d4
  1312.          lea      tenbckw(pc),a0
  1313.          moveq    #4,d3
  1314.          tst.w    d0
  1315.          beq.s    binzero
  1316.          bpl.s    bindecl
  1317.          neg.w    d0
  1318.          bra.s    bindecw
  1319.  
  1320. * Print up a Long Word in binary
  1321. bin2decl movem.l  d0-d7/a0,-(sp)
  1322.          clr.w    d4
  1323.          lea      tenback(pc),a0
  1324.          moveq    #8,d3
  1325.          tst.l    d0
  1326.          beq.s    binzero
  1327.          bpl.s    bindecl
  1328.          neg.l    d0
  1329.  
  1330. bindecw  move.b   #'-',d1
  1331.          bsr      wrchd1
  1332.  
  1333. bindecl  move.l   -(a0),d1
  1334.          clr.w    d2
  1335.  
  1336. bindec1  sub.l    d1,d0
  1337.          bmi.s    bindec2
  1338.          addq.w   #1,d2
  1339.          bra.s    bindec1
  1340.  
  1341. bindec2  add.l    d1,d0
  1342.  
  1343.          tst.w    d2
  1344.          bne.s    bindecz
  1345.          tst.w    d4
  1346.          beq.s    bindec3
  1347.  
  1348. bindecz  move.w   d2,d1
  1349.          add.w    #$30,d1
  1350.          bsr      wrchd1
  1351.          moveq    #1,d4
  1352.  
  1353. bindec3  dbra     d3,bindecl
  1354.          movem.l  (sp)+,d0-d7/a0
  1355.          rts
  1356.  
  1357. * Special Case of Zero
  1358.  
  1359. binzero  move.b   #'0',d0
  1360.          bsr      wrmenu
  1361.          movem.l  (sp)+,d0-d7/a0
  1362.          rts
  1363.  
  1364. * Weird version of WRCHAR that uses d1 instead of d0
  1365.  
  1366. wrchd1   move.l   d0,-(sp)
  1367.          move.l   d1,d0
  1368.          bsr      wrmenu
  1369.          move.l   (sp)+,d0
  1370.          rts
  1371.  
  1372.  
  1373.  
  1374. * Decimal Ascii to Binary routine...
  1375.  
  1376. dec2bin  movem.l  d1-d5/a1,-(sp)
  1377.  
  1378.          clr.l    d0
  1379.          clr.l    d1
  1380.          clr.w    d4
  1381.          lea      tentable(pc),a1
  1382.  
  1383.          move.b   (a0)+,d1
  1384.          cmp.b    #'-',d1
  1385.          seq      d5
  1386.          beq.s    dnumlp
  1387.          cmp.b    #'+',d1
  1388.          bne.s    dnumlp1
  1389.  
  1390. * Main primary loop to find the last digit
  1391.  
  1392. dnumlp   move.b   (a0)+,d1
  1393. dnumlp1  cmp.b    #'0',d1
  1394.          blt.s    atend0
  1395.          cmp.b    #'9',d1
  1396.          bgt.s    atend0
  1397.          addq.w   #1,d4
  1398.          bra.s    dnumlp
  1399.  
  1400. atend0   subq.l   #1,a0
  1401.          subq.w   #1,d4
  1402.          move.l   a0,-(sp)
  1403.  
  1404. * Fall thru into secondary loop to evaluate digits
  1405.  
  1406. atend1   move.b   -(a0),d1
  1407.          move.l   (a1)+,d2
  1408.          and.w    #15,d1
  1409.          subq.w   #1,d1
  1410.          bmi.s    atend3
  1411.          clr.l    d3
  1412.  
  1413. atend2   add.l    d2,d3
  1414.          dbra     d1,atend2
  1415.          add.l    d3,d0
  1416.  
  1417. atend3   dbra     d4,atend1
  1418.  
  1419. * Finished conversion, so check sign here...
  1420.  
  1421.          tst.b    d5
  1422.          beq.s    fincon2
  1423.          neg.l    d0
  1424. fincon2  move.l   (sp)+,a0
  1425.          movem.l   (sp)+,d1-d5/a1
  1426.          rts
  1427.  
  1428.  
  1429.  
  1430. * Set the baud rate
  1431.  
  1432. setbaud  tst.l    baud
  1433.          beq      setbaud2
  1434.  
  1435.          print    mhandle,baudold
  1436.          move.l   baud,d0
  1437.          bsr      bin2decl
  1438.          bsr      nlmenu
  1439. setbaud2 bsr      nlmenu
  1440.  
  1441.          print    mhandle,baudmes
  1442.          bsr      getline
  1443.          tst.l    d0
  1444.          beq      menuagn
  1445.  
  1446.          lea      inputbuf,a0
  1447.          bsr      dec2bin
  1448.  
  1449.          move.l   d0,-(sp)
  1450.          bsr      nlmenu
  1451.          bsr      nlmenu
  1452.          move.l   (sp)+,d0
  1453.  
  1454.          tst.l    d0
  1455.          beq      menuagn
  1456.          bmi      menuagn
  1457.  
  1458.          move.l   d0,baud
  1459.  
  1460.          bsr      abortser
  1461.  
  1462. * Initialise the Serial Port to the selected baud rate.
  1463.  
  1464.          lea      readreq,a1              Point to write request block
  1465.          move.l   baud,IO_BAUD(a1)        Baud Rate
  1466.          move.b   #myflags,IO_SERFLAGS(a1)
  1467.          move.w   #SDCMD_SETPARAMS,IO_COMMAND(a1)
  1468.  
  1469.          move.l   sysbase,a6
  1470.          jsr      _LVODoIO(a6)            Send it!
  1471.  
  1472.          bsr      initser
  1473.  
  1474.          bra      menuagn
  1475.  
  1476.  
  1477.  
  1478. * Initiate the Serial Receive to get a character
  1479.  
  1480. initser  lea      readreq,a1        I request block
  1481.          move.l   #1,IO_LENGTH(a1)  How many characters
  1482.          move.w   #CMD_READ,IO_COMMAND(a1)
  1483.          move.l   #bufin,IO_DATA(a1)
  1484.  
  1485.          move.l   sysbase,a6
  1486.          jmp      _LVOSendIO(a6)
  1487.  
  1488. abortser lea      readreq,a1
  1489.          move.l   sysbase,a6
  1490.          jmp      _LVOAbortIO(a6)
  1491.  
  1492.  
  1493.  
  1494.  
  1495. * Library Definitions :
  1496.  
  1497. thedos   DOSNAME
  1498.          cnop     0,2
  1499.  
  1500. thetrans dc.b     'translator.library',0               * Where's the Macro!??
  1501.          cnop     0,2
  1502.  
  1503. * Device Definitions
  1504.  
  1505. serdevice SERIALNAME
  1506.          cnop     0,2
  1507.  
  1508. nardevice dc.b    'narrator.device',0
  1509.          cnop     0,2
  1510.  
  1511. amaps    dc.b     3,5,10,12            Audio Channel Maps
  1512.          cnop     0,2
  1513.  
  1514. * Textual Definitions
  1515.  
  1516. conname  dc.b     'RAW:0/0/640/200/ArgoTerm 0.20',0
  1517.          cnop     0,2
  1518. sername  dc.b     'SER:',0
  1519.          cnop     0,2
  1520. welcome  dc.b     'ArgoTerm, by Jez San, (c)1986 Argonaut Software Ltd.,'
  1521.          dc.b     ' London, England.',13,10
  1522.          dc.b     'Freeware: No profit must be made from the distribution'
  1523.          dc.b     ' of this program.',13,10
  1524.          dc.b     '[Use the AmigaDOS STACK command to allow a larger Capture '
  1525.          dc.b     'Buffer]',13,10,10
  1526.          dc.b     'Press the HELP key for the Command Menu.',13,10,10,0
  1527.          cnop     0,2
  1528. menutext dc.b     'You may choose from the following options :',13,10,10
  1529.          dc.b     'B - Configure the transmission speed (Baud Rate),',13,10
  1530.          dc.b     'C - Clear (wipe) the Capture Buffer,',13,10
  1531.          dc.b     'D - Download text into the Capture Buffer,',13,10
  1532.          dc.b     'E - Local Echo mode (Half Duplex) on/off,',13,10
  1533.          dc.b     'L - Load a disk file into the Buffer,',13,10
  1534.          dc.b     'Q - Quit this program; terminate session,',13,10
  1535.          dc.b     'T - Turn On/Off the Squalk Mode (narrator),',13,10
  1536.          dc.b     'U - Upload the contents of the Capture Buffer,',13,10
  1537.          dc.b     'X - Xmodem file transmission (aka MODEM7).',13,10,10
  1538.          dc.b     'There are ',0
  1539.          cnop     0,2
  1540. infmess1 dc.b     ' out of ',0
  1541.          cnop     0,2
  1542. infmess2 dc.b     ' characters in the Capture Buffer.',13,10,10
  1543.          dc.b     'Please select one of the above options,',13,10
  1544.          dc.b     'or ESC to return to the terminal session.',13,10,0
  1545.          cnop     0,2
  1546. down1m   dc.b     13,10,'Capturing text now, select DOWNLOAD again to '
  1547.          dc.b     ' finish and store.',13,10,10,0
  1548.          cnop     0,2
  1549. down2m   dc.b     13,10,'File saved, Download is complete.',13,10,10,0
  1550.          cnop     0,2
  1551. upld1m   dc.b     'Text will be upload when you return to the Terminal.'
  1552.          dc.b     13,10,10,0
  1553.          cnop     0,2
  1554. upld2m   dc.b     'Hmmm.. You ARE already uploading!!',13,10,10,0
  1555.          cnop     0,2
  1556. nowset2m dc.b     'Configured for: ',0
  1557.          cnop     0,2
  1558. fullm    dc.b     'Full Duplex.',13,10,10,0
  1559.          cnop     0,2
  1560. halfm    dc.b     'Half Duplex.',13,10,10,0
  1561.          cnop     0,2
  1562. ioerrmes dc.b     'Serial I/O Error!',13,10,0
  1563.          cnop     0,2
  1564. yessqm   dc.b     13,10,'Squalk Mode On!',13,10,10,0
  1565.          cnop     0,2
  1566. notsqm   dc.b     13,10,'Squalk Mode Off!',13,10,10,0
  1567.          cnop     0,2
  1568. warnmes  dc.b     13,10,10,'Memory Full!!  Please SAVE the Buffer!',13,10,10
  1569.          dc.b     'Press any key to enter the menu.',13,10,10,0
  1570.          cnop     0,2
  1571. savemes  dc.b     'Save Buffer.',13,10,10,0
  1572.          cnop     0,2
  1573. filemes  dc.b     13,10,'Please enter the filename : ',0
  1574.          cnop     0,2
  1575. bloadmes dc.b     13,10,10,'File not loaded!',13,10,10,0
  1576.          cnop     0,2
  1577. bsavemes dc.b     13,10,10,'File not saved!',13,10,10,0
  1578.          cnop     0,2
  1579. xmes1    dc.b     13,10,10,'Xmodem transfer; <U>pload or <D>ownload ?',13,10,0
  1580.          cnop     0,2
  1581. upmes1   dc.b     13,10,'Waiting for receiver to start the transfer...',13,10,0
  1582.          cnop     0,2
  1583. uperr1   dc.b     13,10,'Receiver not happy, retrying...',13,10,0
  1584.          cnop     0,2
  1585. updun1   dc.b     13,10,'File transferred safely.',13,10,0
  1586.          cnop     0,2
  1587. cancmes  dc.b     13,10,'For some reason, the transfer has been cancelled.'
  1588.          dc.b     13,10,'Bearing in mind that this could have been line'
  1589.          dc.b     13,10,'noise, you may press <Y> to continue, or any other'
  1590.          dc.b     13,10,'key to abort this transfer.',13,10,10,0
  1591.          cnop     0,2
  1592. rstart1  dc.b     13,10,10,'Initiating the transfer (my NAK has been sent!)'
  1593.          dc.b     13,10,0
  1594.          cnop     0,2
  1595. ret1mes  dc.b     13,10,'No response, re-requesting the block.',13,10,0
  1596.          cnop     0,2
  1597. xrecm2   dc.b     13,10,'File downloaded successfully.',13,10,10
  1598.          dc.b     'Due to XMODEM inaccuracies, the length of the file has '
  1599.          dc.b     'been rounded up to',13,10
  1600.          dc.b     'the next nearest block.  Do you wish to CHOP the '
  1601.          dc.b     'file to the correct length?',0
  1602.          cnop     0,2
  1603. xrecm3   dc.b     13,10,10,'The length of the file is currently : ',0
  1604.          cnop     0,2
  1605. xrecm4   dc.b     13,10,10,'My intelligent estimate of the file length is : ',0
  1606.          cnop     0,2
  1607. askchop  dc.b     13,10,10,'You may either use my Estimate, or your own '
  1608.          dc.b     'figures, or alternatively',13,10
  1609.          dc.b     'you may press RETURN to leave the file at its current '
  1610.          dc.b     'length.'
  1611.          dc.b     13,10,10,'What length would you like this file to be ? ',0
  1612.          cnop     0,2
  1613. slowm1   dc.b     13,10,'Slow (or not enough) response.',13,10,0
  1614.          cnop     0,2
  1615. badblkm  dc.b     13,10,'Bad block received was : ',0
  1616.          cnop     0,2
  1617. dupmes1  dc.b     13,10,'A duplicate block has been received.',13,10,0
  1618.          cnop     0,2
  1619. misschm  dc.b     13,10,'Missed a character in the block.',13,10,0
  1620.          cnop     0,2
  1621. xchksm   dc.b     13,10,'Checksum Error in the block, should have been ',0
  1622.          cnop     0,2
  1623. xchksm1  dc.b     ' but was ',0
  1624.          cnop     0,2
  1625. xchksm2  dc.b     13,10,'Checksum was missing from the block.',13,10,0
  1626.          cnop     0,2
  1627. exitmess dc.b     13,10,10,'To exit: hit a key, and wait patiently!',13,10,10
  1628.          dc.b     0
  1629.          cnop     0,2
  1630. pblokm   dc.b     'Current block : ',0
  1631.          cnop     0,2
  1632. baudmes  dc.b     13,10,10,'Please enter the baud rate, or RETURN to leave '
  1633.          dc.b     'it the same ? ',0
  1634.          cnop     0,2
  1635. baudold  dc.b     13,10,'Current baudrate is : ',0
  1636.          cnop     0,2
  1637.  
  1638.  
  1639.          section     vars,bss
  1640.  
  1641. startbss
  1642.  
  1643.             cnop     0,4
  1644.  
  1645. readreq     ds.l     20    Serial Input Request area
  1646. writereq    ds.l     20    Serial Output Request area
  1647. narread     ds.l     20    Narrator Input
  1648. talkio      ds.l     20    Narrator Output
  1649. read_reply  ds.l     8     Read Reply Port
  1650. write_reply ds.l     8     Write Reply port
  1651. nwriterep   ds.l     8     Narrator write reply
  1652. inputbuf    ds.l     20    Space for some keyboard text!
  1653. filehead    ds.l     8     Space for the filename
  1654.  
  1655. intext      ds.l     64    Input text buffer is 256 bytes
  1656. outtext     ds.l     128   Output phonetic text (512 bytes worth of phonemes!)
  1657.  
  1658.  
  1659. * Long Words
  1660.  
  1661. saveSP   ds.l     1     Initial Stack Pointer
  1662. dosbase  ds.l     1     Base of Dos library
  1663. tranbase ds.l     1     Base of Translator
  1664. chandle  ds.l     1     Handle for Console window
  1665. mhandle  ds.l     1     Handle for Menu Console window
  1666. fhandle  ds.l     1     Handle of diskfile
  1667. bufptr   ds.l     1     Pointer to Capture Buffer
  1668. ubufptr  ds.l     1     Pointer to Uploading text pointer
  1669. bufstart ds.l     1     Pointer to Start Of Buffer
  1670. buflen   ds.l     1     Total maximum size of buffer
  1671. cbuff    ds.l     1     Character Buffer, 1 byte used
  1672. textptr  ds.l     1     Ptr to intext buffer
  1673. lengthin ds.l     1     Length of text in intext
  1674.  
  1675. bufin    ds.l    1      Serial Input Buffer
  1676. bufout   ds.l    1      Serial Output Buffer
  1677. baud     ds.l    1      Current baud rate
  1678.  
  1679.  
  1680. * Words
  1681.  
  1682.  
  1683. * Bytes
  1684.  
  1685.          cnop     0,4
  1686. fileflag ds.b     1     Flag indicating Up/Download status
  1687. duplex   ds.b     1     Full Duplex=0, Half Duplex=$ff
  1688. squalking ds.b    1     Squalking enabled=0
  1689. block    ds.b     1     Block number
  1690.          cnop     0,4
  1691.  
  1692. endbss
  1693.  
  1694.  
  1695.          end
  1696.